home *** CD-ROM | disk | FTP | other *** search
/ SGI Hot Mix 17 / Hot Mix 17.iso / HM17_SGI / research / lib / obsolete / menus.pro < prev    next >
Text File  |  1997-07-08  |  3KB  |  102 lines

  1. ; $Id: menus.pro,v 1.2 1997/01/15 04:02:19 ali Exp $
  2. ;
  3. ; Copyright (c) 1987-1997, Research Systems, Inc.  All rights reserved.
  4. ;       Unauthorized reproduction prohibited.
  5.  
  6. function menus, fcn, choices, help_str
  7. ;+
  8. ; NAME:
  9. ;    MENUS
  10. ;
  11. ; PURPOSE:
  12. ;    Implement a crude menu facility using character strings
  13. ;    at the bottom of an IDL window.  The mouse can be used to select
  14. ;    the different menu items.
  15. ;
  16. ; CATEGORY:
  17. ;    ??
  18. ;
  19. ; CALLING SEQUENCE:
  20. ;    Result = MENUS(Fcn, Choices, Help_Str)
  21. ;
  22. ; INPUTS:
  23. ;    Fcn:    A flag that tells MENUS to either create the menu or allow 
  24. ;        a selection from the menu.  Set Fcn to 0 to draw the original 
  25. ;        choices, drawn on bottom of window.  Set Fcn to 1 to select a 
  26. ;        choice, and to "unhighlight" the previous choice.
  27. ;
  28. ;     Choices:    A string array containing the text for each choice.
  29. ;
  30. ;    Help_str:    A string array with the same number of elements as Choices.  
  31. ;        Help text is displayed on top of the window if the 
  32. ;        corresponding choice is made.
  33. ;
  34. ; OUTPUTS:
  35. ;    MENUS returns the subscript corresponding to the selected Choice, 
  36. ;    from 0 to the number of elements in Choice -1.  If the right button 
  37. ;    is pressed, -1 is returned to indicate done.
  38. ;
  39. ; COMMON BLOCKS:
  40. ;    MENU_COMMON
  41. ;
  42. ; SIDE EFFECTS:
  43. ;    Text is written on the display.
  44. ;
  45. ; RESTRICTIONS:
  46. ;    This simple menu-creation utility is quite crude.  X Windows users 
  47. ;    can create much better user interfaces with the IDL Widgets.  See the 
  48. ;    WIDGETLIB for details.
  49. ;
  50. ; PROCEDURE:
  51. ;    Make menu, allow selections, and exit.
  52. ;
  53. ; MODIFICATION HISTORY:
  54. ;    DMS, December, 1987.
  55. ;    DMS, April, 1989.  Added wait for button debouncing
  56. ;-
  57. ;
  58.  
  59. common menu_common, isel
  60.  
  61. on_error,2                             ;Return to caller if an error occurs
  62. nst = n_elements(choices)
  63. nst1 = 1./nst
  64. ych =  1.0 * !d.y_ch_size / !d.y_vsize ;Char ht in normal units
  65. boxx = [0.,0.,nst1-0.05,nst1-0.05]    ;Box for highlight
  66. boxy = [0.,ych,ych,0.]
  67.  
  68. case fcn of
  69.     ;    Output original choices....
  70. 0:    begin
  71.     for i=0,nst-1 do xyouts,i*nst1, 0., choices(i),/norm,/noclip
  72.     isel = -1
  73.     return,0
  74.     end
  75.  
  76. 1:    begin
  77.     if isel ge 0 then begin        ;Remove old choice
  78.       xyouts,0,1.0-ych,help_str(isel),/norm,col=0,/noclip ;remove instr
  79.       polyfill,(isel * nst1) + boxx,boxy,col=0,/norm ;remove name highl
  80.       xyouts,isel*nst1,0,choices(isel),/norm,col=255,/noclip ;Redraw name
  81.       endif    
  82. ;
  83.     isel = -1
  84.     y = 1000
  85.     repeat tvrdc,x,y,0,/norm until !err eq 0  ;Wait for no buttons
  86.     !err = 0
  87.     while (y gt ych) and (!err ne 4) do $  ;Button hit on bottom or rt but
  88.        tvrdc,x,y,/norm
  89.     if (!err eq 4) then return,-1
  90.     minx = 1000
  91.     for i=0,nst-1 do if ((c = abs(x-(i*nst1)))) lt minx then begin
  92.         minx = c & isel = i
  93.         endif
  94.     polyfill,(isel * nst1) + boxx,boxy,col=255,/norm    ;highlight name
  95.     xyouts,0,1.0-ych,help_str(isel),/norm,/nocl    ;instructions
  96.     xyouts,isel * nst1,0,choices(isel),/norm,col=0,/noclip
  97.     return,isel
  98.     end
  99. else: message, 'Illegal function code'
  100. endcase
  101. end
  102.